package com.ctbri.vSearch.bean.dto;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;


import com.ctbri.vSearch.bean.po.ArticleItem;


public class ArticleAndTermScore {
	//存储所有的查询结果
    private Map<ArticleItem,Double> articleScore = new ConcurrentHashMap<ArticleItem, Double>();
    //存储所有的查询结果
    private Map<ArticleItem, HashMap<String, Float>> termScore = new ConcurrentHashMap<ArticleItem, HashMap<String,Float>>();
    
    //声明比较器并用TreeMap排序
    private ValueComparator vc = new ValueComparator(articleScore);
    private TreeMap<ArticleItem,Double> treeMap = new TreeMap<ArticleItem, Double>(vc);
    
    
    
    public void setTermScore(Map<ArticleItem, HashMap<String, Float>> termScore) {
		this.termScore = termScore;
	}

	public void setTreeMap(TreeMap<ArticleItem, Double> treeMap) {
		this.treeMap = treeMap;
	}

	public Map<ArticleItem, Double> getArticleScore()
    {
//    	TreeMap<ArticleItem,Double> cTreeMap = treeMap;
  //  	this.treeMap.clear();
        return treeMap;
    }

    public Map<ArticleItem, HashMap<String, Float>> getTermScore() {
//    	Map<ArticleItem, HashMap<String, Float>> cTermScore = termScore;
   // 	this.termScore.clear();
        return termScore;
    }
    class ValueComparator implements Comparator<ArticleItem> {
        Map<ArticleItem, Double> base;

        public ValueComparator(Map<ArticleItem, Double> base) {
            this.base = base;
        }
      
        public int compare(ArticleItem a, ArticleItem b) {
            if (base.get(a) >= base.get(b)) {
                return -1;
            } else {
                return 1;
            } // returning 0 would merge keys
        }
    }
	
}
